package com.tv.cms.config;

import cn.dev33.satoken.exception.NotLoginException;
import com.tv.cms.utils.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @project tvcms
 * @description
 * @date 2023/7/20 23:34:13
 */
@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(NotLoginException.class)
    @ResponseBody
    public Result<Object> handleNotLoginException(NotLoginException ex) {
        // 构建错误响应对象
        Result<Object> objectResult = new Result<>();
        objectResult.setCode(50008);
        objectResult.setMessage("Token无效,请重新登录");
        return objectResult;
    }
}

